module.exports = function ($scope, $state, $resource, $timeout, $stateParams, toaster ,spotstateup ,spotstatedown ,spotdelflgdel) {

/* 分页
    * ========================================= */
    $scope.maxSize = 5;            //最多显示多少个按钮
    $scope.bigCurrentPage = 1;      //当前页码
    $scope.itemsPerPage = 10;         //每页显示几条
    $scope.searchform = {};
  
    $scope.load = function () {
        var para = {
          scenicspot_name:$scope.searchform.scenicspot_name,
          pageNo: $scope.bigCurrentPage,
          pageSize: $scope.itemsPerPage,
          scenicarea_id:$stateParams.code
        };
        para = angular.extend($scope.searchform, para);
        $resource('/api/as/ggc/railmapdao/findScenicSpotfromAreaList', {}, {}).save(para,function (res) {
  
          if (res.errcode !== 0) {
            alert("数据获取失败");
            return;
          }
    
          $scope.objs = res.data.results;
          $scope.bigTotalItems = res.data.totalRecord;
          $scope.bigCurrentPage = res.data.pageNo;
    
        });
    };
  $scope.load();
	$scope.myKeyup = function (e) {

		//IE 编码包含在window.event.keyCode中，Firefox或Safari 包含在event.which中
		var keycode = window.event ? e.keyCode : e.which;
		if (keycode == 13) {
			$scope.load();
		}
  };
  
  //上架
	$scope.spotstateup = function (code) {
		spotstateup.get({ 'scenicspot_id': code }, function (res) {
			if (res.data === 1) {
        toaster.success({ title: "提示", body: "上架成功！"});
				$scope.load();
			} else {
				toaster.error({ title: "提示", body: res });
			}
		});
  };
    //下架
	$scope.spotstatedown = function (code) {
		spotstatedown.get({ 'scenicspot_id': code }, function (res) {
			if (res.data === 1) {
        toaster.success({ title: "提示", body: "下架成功！"});
				$scope.load();
			} else {
				toaster.error({ title: "提示", body: res.errmsg });
			}
		});
  };
    //删除
	$scope.spotdelflgdel = function (code) {
    if(confirm("您确认要删除吗？")){
      spotdelflgdel.get({ 'scenicspot_id': code }, function (res) {
        if (res.errcode === 0) {
          toaster.success({ title: "提示", body: "删除成功！"});
          $scope.load();
        } else {
          toaster.error({ title: "提示", body: res.errmsg });
        }
      });
    }
  };
  // 添加景点
  $scope.createspot = function(){
    $state.go('app.createSpot',{'code' : $stateParams.code});
  }

  // 修改景点
  $scope.updatespot = function(scenicspot_id){
    $state.go('app.createSpot',{'scenicspot_id' : scenicspot_id,'code' : $stateParams.code});
  }
}